FROM node:20-alpine AS dev-deps
COPY . /app
WORKDIR /app
RUN npm install

FROM node:20-alpine AS prod-deps
COPY ./package.json /app/
WORKDIR /app
RUN npm install --omit=dev

FROM node:20-alpine AS build
COPY . /app/
COPY --from=dev-deps /app/node_modules /app/node_modules
WORKDIR /app
ARG DASHBOARD_VERSION
ARG DASHBOARD_EDITION
ARG DASHBOARD_API_URL
ARG DASHBOARD_ALLOW_INSECURE
ARG DASHBOARD_AUTH_GITHUB_ENABLED
ARG DASHBOARD_AUTH_GITHUB_CLIENT_ID
ARG DASHBOARD_AUTH_GITHUB_URL
ARG DASHBOARD_AUTH_GITHUB_CALLBACK_URL
ARG DASHBOARD_RESET_PASSWORD_URL
ENV DASHBOARD_VERSION=${DASHBOARD_VERSION} \
    DASHBOARD_EDITION=${DASHBOARD_EDITION} \
    DASHBOARD_API_URL=${DASHBOARD_API_URL} \
    DASHBOARD_ALLOW_INSECURE=${DASHBOARD_ALLOW_INSECURE} \
    DASHBOARD_AUTH_GITHUB_ENABLED=${DASHBOARD_AUTH_GITHUB_ENABLED} \
    DASHBOARD_AUTH_GITHUB_CLIENT_ID=${DASHBOARD_AUTH_GITHUB_CLIENT_ID} \
    DASHBOARD_AUTH_GITHUB_URL=${DASHBOARD_AUTH_GITHUB_URL} \
    DASHBOARD_AUTH_GITHUB_CALLBACK_URL=${DASHBOARD_AUTH_GITHUB_CALLBACK_URL} \
    DASHBOARD_RESET_PASSWORD_URL=${DASHBOARD_RESET_PASSWORD_URL}
RUN npm run build

FROM node:20-alpine
COPY ./package.json /app/
COPY --from=prod-deps /app/node_modules /app/node_modules
COPY --from=build /app/build /app/build
WORKDIR /app
CMD ["npm", "start"]